package cn.magic.basic.service.impl;

import cn.magic.basic.mapper.BaseMapper;
import cn.magic.basic.query.BaseQuery;
import cn.magic.basic.service.IBaseService;
import cn.magic.basic.utils.PageList;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class BaseServiceImpl<T> implements IBaseService<T> {

    @Autowired
    private BaseMapper<T> baseMapper;


    /**
     * @Title: loadAll
     * @Description: 查询部门所有数据
     * @Author: Mr.pc
     * @Version: 1.0
     * @Date:  2022/6/21 17:52
     * @Parameters: []
     * @Return java.util.List<cn.magic.org.domain.T>
     */
    @Override
    public List<T> loadAll() {
        return baseMapper.loadAll();
    }

    /**
     * @Title: loadById
     * @Description: 通过部门id查询数据
     * @Author: Mr.pc
     * @Version: 1.0
     * @Date:  2022/6/21 18:00
     * @Parameters: [id]
     * @Return cn.magic.org.domain.T
     */
    @Override
    public T loadById(Long id) {
        return baseMapper.loadById(id);
    }

    /**
     * @Title: remove
     * @Description: 通过部门id删除数据
     * @Author: Mr.pc
     * @Version: 1.0
     * @Date:  2022/6/21 18:00
     * @Parameters: [id]
     * @Return void
     */
    @Override
    @Transactional
    public void remove(Long id) {
        baseMapper.remove(id);
    }

    /**
     * @Title: update
     * @Description: 通过部门id修改数据
     * @Author: Mr.pc
     * @Version: 1.0
     * @Date:  2022/6/21 18:00
     * @Parameters: [t]
     * @Return void
     */
    @Override
    @Transactional
    public void update(T t) {
        baseMapper.update(t);

    }

    /**
     * @Title: save
     * @Description: 新增数据
     * @Author: Mr.pc
     * @Version: 1.0
     * @Date:  2022/6/21 18:02
     * @Parameters: [t]
     * @Return void
     */
    @Override
    @Transactional
    public void save(T t) {
        baseMapper.save(t);

    }

    /**
     * @Title: queryData
     * @Description: 分页和高级查询
     * @Author: Mr.pc
     * @Version: 1.0
     * @Date:  2022/6/21 18:02
     * @Parameters: [tQuery]
     * @Return java.util.List<cn.magic.org.domain.T>
     */
    @Override
    public PageList<T> queryData(BaseQuery baseQuery) {
        // 查询分页总条数
        Integer total = baseMapper.queryCount(baseQuery);
        // 查询当前页码数据
        List<T> rows = baseMapper.queryData(baseQuery);
        return new PageList<>(total,rows);
    }

    /**
     * @Title: batchDel
     * @Description: 批量删除
     * @Author: Mr.pc
     * @Version: 1.0
     * @Date:  2022/6/25 11:09
     * @Parameters: [ids]
     * @Return void
     */
    @Override
    @Transactional
    public void batchDel(Long[] ids) {
        baseMapper.batchDel(ids);

    }
}
